package com.example.mobile2021606185zhn0427;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class PartRViewAdapter extends RecyclerView.Adapter<PartRViewAdapter.ViewHolder>{
    //    private int[] partId;
//    private String[] partName;
    private List<tingchechang> list;
    public PartRViewAdapter(List<tingchechang> list) {
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_rv_main_part, null);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        tingchechang tingchechang = list.get(position);
        holder.imageView.setImageResource(tingchechang.getPartId());
        holder.textView.setText(tingchechang.getName());
        holder.tvItemempty.setText(String.valueOf(tingchechang.getEmpty()));
        holder.tvItemprice.setText(String.valueOf(tingchechang.getPrice()));
        holder.tvItemkm.setText(String.valueOf(tingchechang.getKm()));
        holder.tvItemadd.setText(tingchechang.getAdd());

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;
        TextView textView;
        TextView tvItemempty;
        TextView tvItemprice;
        TextView tvItemkm;
        TextView tvItemadd;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            this.imageView = itemView.findViewById(R.id.ivItemPart);
            this.textView = itemView.findViewById(R.id.tvItemPart);
            this.tvItemempty = itemView.findViewById(R.id.tvItemempty);
            this.tvItemprice = itemView.findViewById(R.id.tvItemprice);
            this.tvItemkm = itemView.findViewById(R.id.tvItemkm);
            this.tvItemadd = itemView.findViewById(R.id.tvItemadd);
        }
    }
}
